<template>
    <div>
        <h2>========购物车案例 处理数组数据学会习惯使用javascript数组高阶函数===========</h2>
        <table>
            <tr v-for="(item,index) in books" :key="item.id">
                <td v-for="(val,ind) in item" :key="ind">{{val}}</td>
            </tr>
        </table>
        <button @click="click">sfs</button>
        {{total}}
    </div>
</template>

<script>
export default {
  name: 'shopping',
  data() {
    return {
      books:[
        {id:0,name:'《算法》',count:'1',price:'33',num:1},
        {id:1,name:'《算法》',count:'7',price:'33',num:1},
        {id:2,name:'《算法》',count:'9',price:'33',num:1},
      ],
      total:0,
    }
  },
  methods:{
    click() {
        this.total = this.books.reduce(function(prevalue,book){
        	return prevalue + book.price * book.count;
        },0);
    }
  }
}
</script>
      